package com.thread.demo.automic;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @ProjectName: thread-demo
 * @Package: com.thread.demo.automic
 * @ClassName: AutomicIntegerDemo
 * @Author: mac
 * @Description:
 * @Date: 2021/6/9 2:01 下午
 * @Version: 1.0
 */
public class AtomicIntegerDemo {

    final AtomicInteger atomicInteger = new AtomicInteger(5);

    public static void main(String[] args) {
        final AtomicInteger atomicInteger = new AtomicInteger(5);
        int a = atomicInteger.getAndIncrement();
        System.out.println(a);
        System.out.println(atomicInteger.get());
        atomicInteger.incrementAndGet();

    }

    /**
     * 返回当前int类型value值,然后对value值进行自增
     * @return
     */
    int getAndIncrement() {
        int a = atomicInteger.getAndIncrement();
        System.out.println(a);
        System.out.println(atomicInteger.get());
        return a;
    }

    int incrementAndGet(){
        int a = atomicInteger.getAndIncrement();
        System.out.println(a);
        System.out.println(atomicInteger.get());
        return a;
    };
}
